package com.zxt.system;

import com.zxt.bean.AjaxResult;
import com.zxt.controller.common.CommonController;
import com.zxt.dto.SysRoleDTO;
import com.zxt.dto.SysRoleQueryDTO;
import com.zxt.query.QueryResultVO;
import com.zxt.service.ISysRoleService;
import com.zxt.vo.SysRoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 请求处理层-角色信息管理类
 *
 * @author zxt
 */
@Slf4j
@RequestMapping("/system/role")
@RestController
@Api(tags = "角色信息管理接口")
@AllArgsConstructor
public class SysRoleController extends CommonController {

    private final ISysRoleService sysRoleService;

    @ApiOperation(value = "分页查询角色信息", notes = "分页查询角色信息")
    @PostMapping("query")
    public AjaxResult<QueryResultVO<SysRoleVO>> query(@Validated @RequestBody SysRoleQueryDTO dto) {
        QueryResultVO<SysRoleVO> page = sysRoleService.query(dto);
        return AjaxResult.success(page);
    }

    @ApiOperation(value = "创建/更新角色信息", notes = "创建/更新角色信息")
    @PostMapping("addOrUpdate")
    public AjaxResult addOrUpdate(@Validated @RequestBody SysRoleDTO sysRoleDTO) {
        if (sysRoleDTO.getId() == null) {
            sysRoleService.createSysRole(sysRoleDTO);
        } else {
            sysRoleService.updateSysRole(sysRoleDTO);
        }
        return AjaxResult.success();
    }
}
